#include "../logs/gjclog.h"
#include "unistd.h"

void test_log(const std::string &name)
{
    INFO("%s", "开始测试");
    gjclog::Logger::ptr logger = gjclog::LoggerManager::getInstance().getLogger(name);
    logger->debug("%s", "测试日志");
    logger->info("%s", "测试日志");
    logger->warn("%s", "测试日志");
    logger->error("%s", "测试日志");
    logger->fatal("%s", "测试日志");
    INFO("%s", "结束测试");
}

int main()
{
    std::unique_ptr<gjclog::LoggerBuilder> builder(new gjclog::GlobalLoggerBuilder());
    builder->bulidLoggerName("async_logger");
    builder->buildLoggerLevel(gjclog::LogLevel::value::DEBUG);
    builder->buildFormatter("[%c][%f:%l][%p]%m%n");
    builder->buildLoggerType(gjclog::LoggerType::LOGGER_ASYNC);
    builder->buildSink<gjclog::RollByTimeSink>("./logfile/roll-async-by-time", gjclog::TimeGap::GAP_SECOND);
    gjclog::Logger::ptr logger = builder->build();
    size_t cur = gjclog::util::Date::now();
    while(gjclog::util::Date::now() < (cur + 5))
    {
        logger->fatal("拓展测试日志");
        usleep(1000);
    }
    return 0;
}